#pragma semicolon 1
#pragma newdecls required
#include <sourcemod>
#include <sdktools>
#include <adminmenu>

#define TEAM_SURVIVORS 2

#define PLUGIN_VERSION "1.0.1"
#define CVAR_FLAGS FCVAR_SPONLY|FCVAR_NOTIFY
#define NO_ATTACH		0 
#define ATTACH_NORMAL	1 
#define ATTACH_HEAD		2 

#define MENU_DISPLAY_TIME		15
#define DEFAULT_TIMER_FLAGS TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE

int nuclearamount[MAXPLAYERS+1];
int DurationTime[MAXPLAYERS+1];
int DurationTime2[MAXPLAYERS+1];

Handle Cvar_nuclearEnable, Cvar_nuclearAmount, CvarDurationTime, CvarDurationTime2, CvarDamageRadius, CvarCloudRadius, CvarDamageforce, CvarCloudDamage, main_menu, admin_menu;
TopMenuObject nuclear_main_menu;

int redcolor[4] = {255,0,0,255};

Handle timer_handle[MAXPLAYERS+1][128];
Handle hurtdata[MAXPLAYERS+1][128];
Handle Cvar_nuclearTime;

int halo;
int fire;
int white;

public Plugin myinfo = 
{
	name = "nuclear",
	author = "setacina",
	description = "nuclear plugin",
	version = PLUGIN_VERSION,
	url = "https://gitee.com/sweet-and-sour-bombs"
};

public void OnPluginStart()
{

	CreateConVar("L4D2_nuclear_version", PLUGIN_VERSION, " 核弹版本 ", CVAR_FLAGS|FCVAR_SPONLY|FCVAR_NOTIFY);
	
	CvarDurationTime    = CreateConVar("L4D2_nuclear_Duration_Time",  "10",   " 核弹引爆时间 ", CVAR_FLAGS);
	CvarDurationTime2   = CreateConVar("L4D2_nuclear_Duration_Time2", "20",   " 核污染持续时间 ", CVAR_FLAGS);
	Cvar_nuclearEnable  = CreateConVar("L4D2_nuclear_enabled",        "1",    " 开启关闭核弹插件 ", CVAR_FLAGS);
	Cvar_nuclearAmount  = CreateConVar("L4D2_nuclear_amount",         "100",  " 出生时给玩家多少个核弹 ", CVAR_FLAGS);
	Cvar_nuclearTime	= CreateConVar("L4D2_nuclear_time",           "20.0", " 核污染蘑菇云持续时间 ", CVAR_FLAGS);
	CvarDamageRadius	= CreateConVar("L4D2_nuclear_DamageRadius",   "1000", " 核弹爆炸范围 ", CVAR_FLAGS);
	CvarCloudRadius	    = CreateConVar("L4D2_nuclear_DamageRadius",   "1100", " 蘑菇云辐射范围 ", CVAR_FLAGS);
	CvarDamageforce	    = CreateConVar("L4D2_nuclear_Damageforce",    "9000", " 核弹爆发威力 ", CVAR_FLAGS);
	CvarCloudDamage     = CreateConVar("L4D2_nuclear_CouldDamage",    "2",    " 蘑菇云辐射伤害 ", CVAR_FLAGS);
	
	HookEvent("player_spawn", PlayerSpawnEvent);
	HookEvent("player_death", PlayerDeathEvent);

	//AutoExecConfig( true, "l4d2nuclear");
	
	if (LibraryExists("adminmenu") && ((main_menu = GetAdminTopMenu()) != INVALID_HANDLE))
		OnAdminMenuReady(main_menu);
}

public void OnMapStart()
{
	PrecacheSound("ambient/alarms/klaxon1.wav", true);
	PrecacheSound("ambient/explosions/explode_3.wav", true);
	PrecacheSound("animation/gas_station_explosion.wav", true);
	PrecacheSound("animation/van_inside_debris.wav", true);
	PrecacheSound("ambient/random_amb_sfx/dist_explosion_01.wav", true);
	PrecacheSound("ambient/random_amb_sfx/dist_explosion_02.wav", true);
	PrecacheSound("ambient/random_amb_sfx/dist_explosion_03.wav", true);
	PrecacheSound("ambient/random_amb_sfx/dist_explosion_04.wav", true);

	PrecacheModel("models/props_junk/gascan001a.mdl", true);
	PrecacheModel("models/props_junk/propanecanister001a.mdl", true);
	PrecacheModel("models/props_junk/explosive_box001.mdl", true);
	PrecacheModel("models/props_equipment/oxygentank01.mdl", true);
	PrecacheModel("models/missiles/f18_agm65maverick.mdl", true);
	
	PrecacheParticle("gas_explosion_main");
	PrecacheParticle("weapon_pipebomb");
	PrecacheParticle("gas_explosion_pump"); 
	PrecacheParticle("electrical_arc_01_system");
	PrecacheParticle("electrical_arc_01_parent"); 

	fire =PrecacheModel("materials/sprites/laserbeam.vmt");
	white =PrecacheModel("materials/sprites/white.vmt");
	halo = PrecacheModel("materials/dev/halo_add_to_screen.vmt");
}

public void OnAdminMenuReady(Handle menu) 
{
	if (menu == admin_menu)
		return;
	admin_menu = menu;

	AddToTopMenu(admin_menu, "Nuclear Commands", TopMenuObject_Category, Menu_CategoryHandler, INVALID_TOPMENUOBJECT);
	
	TopMenuObject a4d_menu = FindTopMenuCategory(admin_menu, "Nuclear Commands");

	if (a4d_menu == INVALID_TOPMENUOBJECT) 
		return;
	nuclear_main_menu = AddToTopMenu(admin_menu, "nuclear", TopMenuObject_Item, Menu_TopItemHandler, a4d_menu, "nuclear", ADMFLAG_CHEATS);
}

public void Menu_CategoryHandler(TopMenu topmenu, TopMenuAction action, TopMenuObject object_id, int client, char[] buffer, int maxlength) {
	if (action == TopMenuAction_DisplayTitle)
		Format(buffer, maxlength, "Nuclear Commands:");
	else if (action == TopMenuAction_DisplayOption)
		Format(buffer, maxlength, "Nuclear Commands");
}
public void Menu_TopItemHandler(TopMenu topmenu, TopMenuAction action, TopMenuObject object_id, int client, char[] buffer, int maxlength) {

	if (action == TopMenuAction_DisplayOption) 
	{
		if (object_id == nuclear_main_menu)
		Format(buffer, maxlength, "nuclear");
	} 
	else if (action == TopMenuAction_SelectOption)
	{
		if (object_id == nuclear_main_menu)
		nuclearcommand(client, false);
	}
}

public void PrecacheParticle(char[] particlename)
{
	int particle = CreateEntityByName("info_particle_system");
	
	if (IsValidEdict(particle))
	{
		DispatchKeyValue(particle, "effect_name", particlename);
		DispatchKeyValue(particle, "targetname", "particle");
		DispatchSpawn(particle);
		ActivateEntity(particle);
		AcceptEntityInput(particle, "start");
		CreateTimer(0.01, DeleteParticles, particle);
	} 
}

public void CreateParticles(float pos[3], char[] particlename, float time)
{
	int particle = CreateEntityByName("info_particle_system");
	
	if (IsValidEdict(particle))
	{
		TeleportEntity(particle, pos, NULL_VECTOR, NULL_VECTOR);
		DispatchKeyValue(particle, "effect_name", particlename);
		DispatchKeyValue(particle, "targetname", "particle");
		DispatchSpawn(particle);
		ActivateEntity(particle);
		AcceptEntityInput(particle, "start");
		CreateTimer(time, DeleteParticles, particle);
	} 
}

public Action DeleteParticles(Handle timer, any particle) 
{ 	
	if (IsValidEdict(particle)) 
	{ 		
		char classname[64]; 		
		GetEdictClassname(particle, classname, sizeof(classname)); 		 		
		if (StrEqual(classname, "info_particle_system", false)) 
		{
			RemoveEdict(particle); 		
		} 	
	} 
	return Plugin_Continue;
}

bool TraceEntityFilterPlayer(int entity, int contentsMask)
{
	return entity > MaxClients || !entity;
} 

public Action nuclearcommand(int client, int args)
{
	if (GetConVarInt(Cvar_nuclearEnable))
	{
		if (client > 0 && IsClientInGame(client))
		{	
			if (IsPlayerAlive(client))
			{
				if (nuclearamount[client] > 0)
				{
					float vAngles[3];
					float vOrigin[3];
					float pos[3];

					GetClientEyePosition(client,vOrigin);
					GetClientEyeAngles(client, vAngles);

					Handle trace = TR_TraceRayFilterEx(vOrigin, vAngles, MASK_SHOT, RayType_Infinite, TraceEntityFilterPlayer);
					
					TE_SetupSparks(pos, NULL_VECTOR, 2, 1);
					TE_SendToAll(0.1);
					TE_SetupSparks(pos, NULL_VECTOR, 2, 2);
					TE_SendToAll(0.4);
					TE_SetupSparks(pos, NULL_VECTOR, 1, 1);
					TE_SendToAll(1.0);
					
					if(TR_DidHit(trace))
					{
						TR_GetEndPosition(pos, trace);
						pos[2] += 15.0;
					}
					
					CloseHandle(trace);
					
					int nuclear = CreateEntityByName("prop_dynamic");
					
					if (IsValidEdict(nuclear))
					{
                        SetEntityModel(nuclear, "models/missiles/f18_agm65maverick.mdl");
                        DispatchKeyValueVector(nuclear, "origin", pos);
                        DispatchKeyValue(nuclear, "angles", "0 135 11");
                        DispatchKeyValue(nuclear, "spawnflags", "0");
                        DispatchKeyValue(nuclear, "rendercolor", "255 255 255");
                        DispatchKeyValue(nuclear, "renderamt", "255");
                        DispatchKeyValue(nuclear, "solid", "6");
                        DispatchKeyValue(nuclear, "MinAnimTime", "5");
                        DispatchKeyValue(nuclear, "MaxAnimTime", "10");
                        DispatchKeyValue(nuclear, "fademindist", "1500");
                        DispatchKeyValue(nuclear, "fadescale", "1");
                        DispatchKeyValue(nuclear, "model", "models/missiles/f18_agm65maverick.mdl");
                        SetEntData(nuclear, GetEntSendPropOffs(nuclear, "m_CollisionGroup"), 1, 1, true);
                        DispatchKeyValue(nuclear, "parentname", "helis");
                        DispatchKeyValue(nuclear, "fademaxdist", "3600");
                        DispatchKeyValue(nuclear, "classname", "prop_dynamic");
                        DispatchSpawn(nuclear);
                        TeleportEntity(nuclear, pos, NULL_VECTOR, NULL_VECTOR);
	
                        SetEntProp(nuclear, Prop_Send, "m_iGlowType", 3 );
                        SetEntProp(nuclear, Prop_Send, "m_nGlowRange", 0 );
                        SetEntProp(nuclear, Prop_Send, "m_glowColorOverride", 700000);

                        CreateTimer( 10.0, removenuclear, nuclear );
                     
                        DurationSound(client, GetConVarInt(CvarDurationTime));
                        
                        pos[1] += 50;
                        pos[0] -= 50;
                        pos[2] -= 5;
                        
                        TE_SetupBeamRingPoint(pos, 10.0, 300.0, fire, halo, 0, 20, 2.0, 8.0, 0.0, redcolor, 10, 0);
                        TE_SendToAll();
		
                        TE_SetupBeamRingPoint(pos, 10.0, 260.0, fire, halo, 0, 20, 4.0, 10.0, 0.0, redcolor, 10, 0);
                        TE_SendToAll();
		
                        TE_SetupBeamRingPoint(pos, 10.0, 220.0, fire, halo, 0, 20, 6.0, 8.0, 0.0, redcolor, 10, 0);
                        TE_SendToAll();
		
                        TE_SetupBeamRingPoint(pos, 10.0, 180.0, fire, halo, 0, 20, 8.0, 10.0, 0.0, redcolor, 10, 0);
                        TE_SendToAll();

                        TE_SetupBeamRingPoint(pos, 10.0, 130.0, fire, halo, 0, 20, 10.0, 8.0, 0.0, redcolor, 10, 0);
                        TE_SendToAll();
						
                        CreateParticles(pos,"electrical_arc_01_system", 5.0 );
                        CreateParticles(pos,"electrical_arc_01_parent", 5.0 ); 
                    }						

					FakeClientCommand(client, "say_team 我引爆了核弹, 速离开!");
					
					Handle gasdata = CreateDataPack();
					CreateTimer(11.0, CreateCloud, gasdata);
					WritePackCell(gasdata, client);
					WritePackFloat(gasdata, pos[0]);
					WritePackFloat(gasdata, pos[1]);
					WritePackFloat(gasdata, pos[2]);
					WritePackCell(gasdata, nuclearamount[client]);
					nuclearamount[client]--;
					
					Handle bombdata = CreateDataPack();
					CreateTimer(10.0, CreateExplode, bombdata);
					WritePackCell(bombdata, client);
					WritePackFloat(bombdata, pos[0]);
					WritePackFloat(bombdata, pos[1]);
					WritePackFloat(bombdata, pos[2]);
					WritePackCell(bombdata, nuclearamount[client]);
				}
				else
				{
					PrintToChat(client, "[SM] 无法获取核弹");
				}
			}
		}
	}
	else
	{
		PrintToChat(client, "[SM] 核弹正在准备当中.  请等待....");
	}
	return Plugin_Handled;
}
public Action Createpush(Handle timer, Handle pushdata)
{
	ResetPack(pushdata);
	float location[3];
	location[0] = ReadPackFloat(pushdata);
	location[1] = ReadPackFloat(pushdata);
	location[2] = ReadPackFloat(pushdata);
	
	//PrintToChatAll("DEBUG 1-2 测试成功 冲击波出现");
	
	int push = CreateEntityByName("point_push");
	
	if( IsValidEntity(push) )
	{
		DispatchKeyValueFloat (push, "magnitude", 9999.0);                     
		DispatchKeyValueFloat (push, "radius", 1000.0);                     
		SetVariantString("spawnflags 24");                     
		AcceptEntityInput(push, "AddOutput");
		DispatchSpawn(push);   
		TeleportEntity(push, location, NULL_VECTOR, NULL_VECTOR);  
		AcceptEntityInput(push, "Enable", -1, -1);
	}

	CreateTimer(0.8, DeletePushForce, push);
	return Plugin_Continue;
}

public Action CreateHurt(Handle timer, Handle hurt)
{
	ResetPack(hurt);
	int client = ReadPackCell(hurt);
	int nuclearNumber = ReadPackCell(hurt);
	float location[3];
	location[0] = ReadPackFloat(hurt);
	location[1] = ReadPackFloat(hurt);
	location[2] = ReadPackFloat(hurt);
	KillTimer(timer);
	timer_handle[client][nuclearNumber] = INVALID_HANDLE;
	CloseHandle(hurt);
	
	char originData[64];
	Format(originData, sizeof(originData), "%f %f %f", location[0], location[1], location[2]);
	
	char nuclearRadius[64];
	Format(nuclearRadius, sizeof(nuclearRadius), "%i", GetConVarInt(CvarDamageRadius));
	
	char nuclearDamage[64];
	Format(nuclearDamage, sizeof(nuclearDamage), "%i", GetConVarInt(CvarDamageforce));

	int pointHurt = CreateEntityByName("point_hurt");
	
	if( IsValidEntity(pointHurt) )
	{
		DispatchKeyValue(pointHurt,"Origin", originData);
		DispatchKeyValue(pointHurt,"Damage", nuclearDamage);
		DispatchKeyValue(pointHurt,"DamageRadius", nuclearRadius);
		DispatchKeyValue(pointHurt,"DamageDelay", "1.0");
		DispatchKeyValue(pointHurt,"DamageType", "65536");
		DispatchKeyValue(pointHurt,"classname","point_hurt");
		DispatchSpawn(pointHurt);
		AcceptEntityInput(pointHurt, "TurnOn");
	}
	
	CreateTimer(0.5, DeletePointHurt, pointHurt); 
	return Plugin_Continue;
}

public Action CreateExplode(Handle timer, Handle bombdata)
{
	ResetPack(bombdata);
	int client = ReadPackCell(bombdata);
	float location[3];
	location[0] = ReadPackFloat(bombdata);
	location[1] = ReadPackFloat(bombdata);
	location[2] = ReadPackFloat(bombdata);
	int nuclearNumber = ReadPackCell(bombdata);
	CloseHandle(bombdata);
	
	EmitSoundToAll("animation/gas_station_explosion.wav", _, _, _, _, 0.8);
	EmitSoundToAll("ambient/explosions/explode_3.wav", _, _, _, _, 0.8);

	PyroExplode(location);
	PyroExplode2(location);
	
	hurtdata[client][nuclearNumber] = CreateDataPack();
	WritePackCell(hurtdata[client][nuclearNumber], client);
	WritePackCell(hurtdata[client][nuclearNumber], nuclearNumber);
	WritePackFloat(hurtdata[client][nuclearNumber], location[0]);
	WritePackFloat(hurtdata[client][nuclearNumber], location[1]);
	WritePackFloat(hurtdata[client][nuclearNumber], location[2]);
	timer_handle[client][nuclearNumber] = CreateTimer(0.1, CreateHurt, hurtdata[client][nuclearNumber], TIMER_REPEAT);
					
	Handle pushdata = CreateDataPack();
	CreateTimer(0.1, Createpush, pushdata);
	WritePackFloat(pushdata, location[0]);
	WritePackFloat(pushdata, location[1]);
	WritePackFloat(pushdata, location[2]);	
	
	int explosion =  CreateEntityByName("prop_physics");
	
	if( IsValidEntity(explosion) )      
    {	
        SetEntPropEnt(explosion, Prop_Data, "m_hOwnerEntity", client);
        SetEntProp(explosion, Prop_Send, "m_CollisionGroup", 1);
        //DispatchKeyValue(explosion, "model", "models/props_junk/explosive_box001.mdl");
        DispatchKeyValue(explosion, "model", "models/props_junk/propanecanister001a.mdl");
        //DispatchKeyValue(explosion, "model", "models/props_equipment/oxygentank01.mdl");
        DispatchKeyValue(explosion, "model", "models/props_junk/gascan001a.mdl");		
        DispatchSpawn(explosion);
		
        TeleportEntity(explosion, location, NULL_VECTOR, NULL_VECTOR);
        AcceptEntityInput(explosion, "break");
		
        location[2] += 50;
        CreateParticles(location, "gas_explosion_main", 1.0); 
        CreateParticles(location, "gas_explosion_pump", 1.0);
        CreateParticles(location, "weapon_pipebomb", 1.0); 
        
        location[2] += 100;
        CreateParticles(location, "gas_explosion_main", 1.0); 
        CreateParticles(location, "gas_explosion_pump", 1.0);
        CreateParticles(location, "weapon_pipebomb", 1.0); 
       
        location[0] += 50;
        location[1] -= 50;
        CreateParticles(location, "gas_explosion_main", 1.0); 
        CreateParticles(location, "gas_explosion_pump", 1.0);
        CreateParticles(location, "weapon_pipebomb", 1.0); 
        
        location[0] -= 100;
        location[1] += 100;
        CreateParticles(location, "gas_explosion_main", 1.0); 
        CreateParticles(location, "gas_explosion_pump", 1.0);
        CreateParticles(location, "weapon_pipebomb", 1.0); 
        
        location[2] += 100;
        location[0] += 200;
        location[1] -= 200;
        CreateParticles(location, "gas_explosion_main", 1.0); 
        CreateParticles(location, "gas_explosion_pump", 1.0);
        CreateParticles(location, "weapon_pipebomb", 1.0); 
        
	    //CreateParticles(location, "fire_tanker", 10.0); //no smoke
	    //CreateParticles(location, "fire_window", 10.0); //smoke
	    //CreateParticles(location, "tankwall_concrete", 10.0); 
	    //CreateParticles(location, "fire_barrel_big", 10.0);  //smoke
        //CreateParticles(location, "Molotov_groundfire", 10.0); 
        //CreateParticles(location, "weapon_pipebomb", 10.0); 
        //CreateParticles(location, "env_fire_large_smoke", 10.0);
	}

	Handle hShake = StartMessageOne("Shake", client);
	
	if (hShake != INVALID_HANDLE)
    {
        BfWriteByte(hShake, 0);
        BfWriteFloat(hShake, 10.0);
        BfWriteFloat(hShake, 5.0);
        BfWriteFloat(hShake, 15.0);
        EndMessage();
    }
	return Plugin_Continue;
}

public Action CreateCloud(Handle timer, Handle gasdata)
{
	ResetPack(gasdata);
	int client = ReadPackCell(gasdata);
	float location[3];
	location[0] = ReadPackFloat(gasdata);
	location[1] = ReadPackFloat(gasdata);
	location[2] = ReadPackFloat(gasdata);
	int nuclearNumber = ReadPackCell(gasdata);
	CloseHandle(gasdata);

	location[2] += 200;
	location[0] -= 100;
	location[1] += 100;
	CreateParticles(location, "gas_explosion_main", 1.0); 
	CreateParticles(location, "gas_explosion_pump", 1.0);
	CreateParticles(location, "weapon_pipebomb", 1.0); 
	
	location[2] += 100;
	location[0] += 200;
	location[1] -= 200;
	CreateParticles(location, "gas_explosion_main", 1.0); 
	CreateParticles(location, "gas_explosion_pump", 1.0);
	CreateParticles(location, "weapon_pipebomb", 1.0); 
		
	location[2] -= 300;
	location[0] -= 100;
	location[1] += 100;
		
	char colorData[64];
	
	int red =  255;
	int green =  255;
	int blue =255;
	Format(colorData, sizeof(colorData), "%i %i %i", red, green, blue);
	
	char originData[64];
	
	Format(originData, sizeof(originData), "%f %f %f", location[0], location[1], location[2]);
	
	char nuclearRadius[64];
	Format(nuclearRadius, sizeof(nuclearRadius), "%i", GetConVarInt(CvarCloudRadius));
	
	char nuclearDamage[64];
	Format(nuclearDamage, sizeof(nuclearDamage), "%i", GetConVarInt(CvarCloudDamage));

	int pointHurt = CreateEntityByName("point_hurt");
	
	if( IsValidEntity(pointHurt) )
	{
		DispatchKeyValue(pointHurt,"Origin", originData);
		DispatchKeyValue(pointHurt,"Damage", nuclearDamage);
		DispatchKeyValue(pointHurt,"DamageRadius", nuclearRadius);
		DispatchKeyValue(pointHurt,"DamageDelay", "1.0");
		DispatchKeyValue(pointHurt,"DamageType", "65536");
		DispatchKeyValue(pointHurt,"classname","point_hurt");
		DispatchSpawn(pointHurt);
		AcceptEntityInput(pointHurt, "TurnOn");
	}

	CreateTimer(50.0, DeletePointHurt, pointHurt); 
	
	PrintToChatAll("\x04[核辐射污染]   \x05范围 \x01+%d  \x05伤害值 \x01+%d  \x05持续时间 \x01+50 \x05秒",GetConVarInt(CvarDamageRadius),GetConVarInt(CvarCloudDamage));
	
	char cloud_name[128];
	Format(cloud_name, sizeof(cloud_name), "Gas%i", client);
	int Cloud = CreateEntityByName("env_smokestack");
	DispatchKeyValue(Cloud,"targetname", cloud_name);
	DispatchKeyValue(Cloud,"Origin", originData);
	DispatchKeyValue(Cloud,"BaseSpread", "50");
	DispatchKeyValue(Cloud,"SpreadSpeed", "10");
	DispatchKeyValue(Cloud,"Speed", "40");
	DispatchKeyValue(Cloud,"StartSize", "200");
	DispatchKeyValue(Cloud,"EndSize", "1400");
	DispatchKeyValue(Cloud,"Rate", "15");
	DispatchKeyValue(Cloud,"JetLength", "1000");
	DispatchKeyValue(Cloud,"Twist", "10");
	DispatchKeyValue(Cloud,"RenderColor", colorData);
	DispatchKeyValue(Cloud,"RenderAmt", "100");
	DispatchKeyValue(Cloud,"SmokeMaterial", "particle/particle_noisesphere.vmt");
	DispatchSpawn(Cloud);
	AcceptEntityInput(Cloud, "TurnOn");
	EmitSoundToAll("animation/van_inside_debris.wav", _, _, _, _, 0.8);

	Handle soundpack1 = CreateDataPack();
	CreateTimer(5.0, DurationSoundtime1, soundpack1);
	WritePackCell(soundpack1, client);
	
	Handle soundpack2 = CreateDataPack();
	CreateTimer(7.0, DurationSoundtime2, soundpack2);
	WritePackCell(soundpack2, client);
	
	Handle soundpack3 = CreateDataPack();
	CreateTimer(9.0, DurationSoundtime3, soundpack3);
	WritePackCell(soundpack3, client);
	
	Handle soundpack4 = CreateDataPack();
	CreateTimer(11.0, DurationSoundtime4, soundpack4);
	WritePackCell(soundpack4, client);

	Handle entitypack = CreateDataPack();
	CreateTimer(GetConVarFloat(Cvar_nuclearTime), RemoveGas, entitypack);
	CreateTimer(GetConVarFloat(Cvar_nuclearTime), KillGas, entitypack);
	WritePackCell(entitypack, Cloud);
	WritePackCell(entitypack, nuclearNumber);
	WritePackCell(entitypack, client);
	return Plugin_Continue;
}

public Action DeletePointHurt(Handle timer, any ent)
{
	if (IsValidEntity(ent))
	{
		char classname[64];
		GetEdictClassname(ent, classname, sizeof(classname));
		if (StrEqual(classname, "point_hurt", false))
		{
			AcceptEntityInput(ent, "Kill"); 
			RemoveEdict(ent);
		}
	}
	return Plugin_Continue;
}

public Action DeletePushForce(Handle timer, any ent)
{
	if (IsValidEntity(ent))
	{
		char classname[64];
		GetEdictClassname(ent, classname, sizeof(classname));
		if (StrEqual(classname, "point_push", false))
		{
 			AcceptEntityInput(ent, "Disable");
			AcceptEntityInput(ent, "Kill"); 
			RemoveEdict(ent);
		}
	}
	return Plugin_Continue;
}

public Action RemoveGas(Handle timer, Handle entitypack)
{
	ResetPack(entitypack);
	int Cloud = ReadPackCell(entitypack);
	int nuclearNumber = ReadPackCell(entitypack);
	int client = ReadPackCell(entitypack);

	if (IsValidEntity(Cloud))
	{
		AcceptEntityInput(Cloud, "TurnOff");	
	}
	if (timer_handle[client][nuclearNumber] != INVALID_HANDLE)
	{
		KillTimer(timer_handle[client][nuclearNumber]);
		timer_handle[client][nuclearNumber] = INVALID_HANDLE;
		CloseHandle(hurtdata[client][nuclearNumber]);
	}
	return Plugin_Continue;
}

public Action KillGas(Handle timer, Handle entitypack)
{
	ResetPack(entitypack);
	int Cloud = ReadPackCell(entitypack);
	PrintToChatAll("\x04核污染蘑菇云消失");
	if (IsValidEntity(Cloud))
		AcceptEntityInput(Cloud, "Kill");
	
	CloseHandle(entitypack);
	return Plugin_Continue;
}

public Action PyroExplode(float vec1[3])
{
	int color[4]={188,220,255,250};
	TE_SetupBeamRingPoint(vec1, 5.0, 2000.0, white, halo, 0, 8, 1.5, 12.0, 0.5, color, 8, 0);
  	TE_SendToAll();
	return Plugin_Continue;
}

public void PyroExplode2(float vec1[3])
{
	vec1[2] += 10;
	int color[4]={188,220,255,250};			
	TE_SetupBeamRingPoint(vec1, 5.0, 1600.0, fire, halo, 0, 60, 8.0, 200.0, 0.2, color, 20, 0);
  	TE_SendToAll();
}

public Action removenuclear(Handle timer, any ent)
{
	if (IsValidEntity(ent))
	{
		char classname[64];
		GetEdictClassname(ent, classname, sizeof(classname));
		if (StrEqual(classname, "prop_dynamic", false))
		{
			RemoveEdict(ent);		
		}
	}
	return Plugin_Continue;
}

public void PlayerSpawnEvent(Event event, const char[] name, bool dontBroadcast)
{
	int client = GetClientOfUserId(GetEventInt(event, "userid"));
	nuclearamount[client] = GetConVarInt(Cvar_nuclearAmount);
}

public void PlayerDeathEvent(Event event, const char[] name, bool dontBroadcast)
{
	int client = GetClientOfUserId(GetEventInt(event, "userid"));
	nuclearamount[client] = 0;
}

public Action DurationSoundtime1(Handle timer, Handle soundpack)
{
	ResetPack(soundpack);
	int client = ReadPackCell(soundpack);
	DurationSound2(client, GetConVarInt(CvarDurationTime2));
	return Plugin_Continue;
}

public Action DurationSoundtime2(Handle timer, Handle soundpack)
{
	ResetPack(soundpack);
	int client = ReadPackCell(soundpack);
	DurationSound3(client, GetConVarInt(CvarDurationTime2));
	return Plugin_Continue;
}

public Action DurationSoundtime3(Handle timer, Handle soundpack)
{
	ResetPack(soundpack);
	int client = ReadPackCell(soundpack);
	DurationSound4(client, GetConVarInt(CvarDurationTime2));
	return Plugin_Continue;
}

public Action DurationSoundtime4(Handle timer, Handle soundpack)
{
	ResetPack(soundpack);
	int client = ReadPackCell(soundpack);
	DurationSound5(client, GetConVarInt(CvarDurationTime2));
	return Plugin_Continue;
}
void DurationSound2(int client, int time)
{
	DurationTime2[client] = time;
	CreateTimer(1.0, Timer_Freeze2, client, DEFAULT_TIMER_FLAGS);
}
void DurationSound3(int client, int time)
{
	DurationTime2[client] = time;
	CreateTimer(1.0, Timer_Freeze2, client, DEFAULT_TIMER_FLAGS);
}
void DurationSound4(int client, int time)
{
	DurationTime2[client] = time;
	CreateTimer(1.0, Timer_Freeze2, client, DEFAULT_TIMER_FLAGS);
}
void DurationSound5(int client, int time)
{
	DurationTime2[client] = time;
	CreateTimer(1.0, Timer_Freeze2, client, DEFAULT_TIMER_FLAGS);
}
public Action Timer_Freeze2(Handle timer, any value)
{
	int client = value & 0x7f;

	DurationTime2[client]--;
	if( DurationTime2[client] >= 1)
	{
	    EmitSoundToAll("ambient/random_amb_sfx/dist_explosion_01.wav" ,_, _, _, _, 1.0);
	}
	else
	{
		return Plugin_Stop;
	}
	return Plugin_Handled;
}
public Action Timer_Freeze3(Handle timer, any value)
{
	int client = value & 0x7f;

	DurationTime2[client]--;
	if( DurationTime2[client] >= 1)
	{
	    EmitSoundToAll("ambient/random_amb_sfx/dist_explosion_02.wav" ,_, _, _, _, 1.0);
	}
	else
	{
		return Plugin_Stop;
	}
	return Plugin_Handled;
}
public Action Timer_Freeze4(Handle timer, any value)
{
	int client = value & 0x7f;

	DurationTime2[client]--;
	if( DurationTime2[client] >= 1)
	{
	    EmitSoundToAll("ambient/random_amb_sfx/dist_explosion_03.wav" ,_, _, _, _, 1.0);
	}
	else
	{
		return Plugin_Stop;
	}
	return Plugin_Handled;
}
public Action Timer_Freeze5(Handle timer, any value)
{
	int client = value & 0x7f;

	DurationTime2[client]--;
	if( DurationTime2[client] >= 1)
	{
	    EmitSoundToAll("ambient/random_amb_sfx/dist_explosion_04.wav" ,_, _, _, _, 1.0);
	}
	else
	{
		return Plugin_Stop;
	}
	return Plugin_Handled;
}
void DurationSound(int client, int time)
{
	DurationTime[client] = time;
	CreateTimer(1.0, Timer_Freeze, client, DEFAULT_TIMER_FLAGS);
}

public Action Timer_Freeze(Handle timer, any value)
{
	int client = value & 0x7f;

	DurationTime[client]--;
	if( DurationTime[client] >= 1)
	{
	    EmitSoundToAll("ambient/alarms/klaxon1.wav" ,_, _, _, _, 0.8);
	    PrintHintTextToAll("核弹启爆倒计时\n %d 秒", DurationTime[client]);
	}
	else
	{
		return Plugin_Stop;
	}
	return Plugin_Handled;
}
